package com.weetop.akly.presenter;

import android.app.Activity;
import android.util.Log;

import com.weetop.akly.base.mvp.BaseModel;
import com.weetop.akly.base.mvp.BaseObserver;
import com.weetop.akly.base.mvp.BasePresenter;
import com.weetop.akly.bean.LoginBean;
import com.weetop.akly.view.LoginView;

import java.util.HashMap;

public class LoginPresent extends BasePresenter<LoginView> {
    private static final String TAG = "LoginPresent";
    public LoginPresent(LoginView baseView, Activity activity) {
        super(baseView, activity);
    }

    public void toLogin(String phone ,String password){
        HashMap<String, String> data = myApplication.getGlobalData();
        data.put("account", phone);
        data.put("password", password);
        addDisposable(apiServer.toLogin(data), new BaseObserver<BaseModel<LoginBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<LoginBean> o) {
                Log.d(TAG, "onSuccess: "+o.toString());
                baseView.loginSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }



}
